package com.mingtu.jgspatrol.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.StringUtils;
import com.bumptech.glide.Glide;
import com.github.chrisbanes.photoview.PhotoView;
import com.mingtu.common.base.BaseApplication;
import com.mingtu.jgspatrol.R;
import com.mingtu.infrared.bean.InfraredRecordImgBean;
import com.youth.banner.adapter.BannerAdapter;

import java.util.List;

public class PhotoAdapter extends BannerAdapter<InfraredRecordImgBean.DataBean.ListBean, PhotoAdapter.ActivityHolder> {

    private Context context;

    public PhotoAdapter(Context context, List<InfraredRecordImgBean.DataBean.ListBean> datas) {
        super(datas);
        this.context = context;
    }

    @Override
    public ActivityHolder onCreateHolder(ViewGroup parent, int viewType) {
        // 实例化展示的view
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_photo, parent, false);
        // 实例化viewholder
        ActivityHolder viewHolder = new ActivityHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindView(ActivityHolder holder, InfraredRecordImgBean.DataBean.ListBean data, int position, int size) {
        if (data != null) {
            String imgURL = data.getUrl();
            if (!StringUtils.isEmpty(imgURL)) {
                Glide.with(context)
                        .load(imgURL)
                        .apply(BaseApplication.getRequestOptions())
                        .into(holder.photoView);
            }
        }

    }

    public class ActivityHolder extends RecyclerView.ViewHolder {
        private final View view;
        private final PhotoView photoView;

        public ActivityHolder(View itemView) {
            super(itemView);
            view = itemView;
            photoView = (PhotoView) view.findViewById(R.id.photo_view);

        }
    }
}
